#*- coding: UTF-8 -*-
from Tkinter import *
import tkFont
import pickle
from ListeHighScore import *

class modele():
    def __init__(self, joueur = None):
        self.listeHighScore = ListeHighScore()
        if joueur:
            self.listeHighScore.finDePartieScore(joueur)
        self.saveScore()
        
            

    def saveScore(self):
        p = pickle.Pickler(open("highscore.agile", 'w'))
        p.dump(self.listeHighScore)

    def imprimerScore(self):
        for i in self.listeScore:
            print i.nom, i.score

class vue():
    #def __init__(self, parentGUI, partie, width, height):
    #    root = Frame(parentGUI)
    #    self.root = root
    def __init__(self,parent):
        self.taille=400
        self.frame=Frame(parent.win, width=self.taille, height=self.taille, bg="black")
        self.frame.pack(side=TOP)
        self.controleur = parent
        self.font = tkFont.Font (family='Castellar', size=16, weight="bold")
        self.fontTitre = tkFont.Font (family='Castellar', size=30, weight="bold")

    def afficherHighScore(self):
        listeScore = self.controleur.getListeScore()
        
        a=Label(self.frame, width=10, text = "HIGHSCORES", font=self.fontTitre, fg="White", bg="black").grid(sticky=W, columnspan=2, column=0, row=0)
        
        j=1

        for i in listeScore:
            if i.score > 0:
                Label(self.frame, text = i.nom, font=self.font, fg="red", bg="black").grid(sticky=W, column=0, row=j)
                Label(self.frame, width=5, text = i.score, font=self.font, fg="red", bg="black", justify=LEFT).grid(sticky=W, column=1, row=j)
                j+=1
            


class Controleur():
    def __init__(self, parent):
        win = Toplevel(parent)
        self.win = win
        self.modele = modele()
        self.vue=vue(self)
        #self.vue.parent = self
        #self.modele.imprimerScore()
        self.vue.afficherHighScore()
        try:
            win.focus_set()
            win.grab_set()
            win.mainloop()
            win.destroy()
        except:
            pass
    
    def getListeScore(self):
        print self.modele.listeHighScore.listeScore
        return self.modele.listeHighScore.listeScore
        

        

    
if __name__ == '__main__':
    
    controleur=Controleur()